home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / crtdel / RCS / crtdel.c,v < prev   
Encoding:
Text File  |  1989-09-15  |  4.1 KB  |  187 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     89.09.15.11.22.00;  author brent;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     89.09.13.20.49.17;  author ouster;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     89.09.13.11.29.07;  author ouster;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @@
  27.  
  28.  
  29. 1.3
  30. log
  31. @Fixed usage print statement
  32. @
  33. text
  34. @/* 
  35.  * crtdel.c --
  36.  *
  37.  *    This program is a stand-alone benchmark that measures
  38.  *    the cost of doing the following:  create a file,
  39.  *    write some bytes to it, close the file, open in read
  40.  *    mode, read all the bytes, close the file, delete the
  41.  *    file.  It should be invoked as follows:
  42.  *
  43.  *    crtdel fileName kBytes count
  44.  *
  45.  *    "fileName" is the name of the file, "kBytes" tells
  46.  *    how many kbytes to write to it, and "count" tells how
  47.  *    many times to repeat the experiment.
  48.  *
  49.  * Copyright 1989 Regents of the University of California.
  50.  * Permission to use, copy, modify, and distribute this
  51.  * software and its documentation for any purpose and without
  52.  * fee is hereby granted, provided that the above copyright
  53.  * notice appear in all copies.  The University of California
  54.  * makes no representations about the suitability of this
  55.  * software for any purpose.  It is provided "as is" without
  56.  * express or implied warranty.
  57.  */
  58.  
  59. #ifndef lint
  60. static char rcsid[] = "$Header: /sprite/src/benchmarks/crtdel/RCS/crtdel.c,v 1.2 89/09/13 20:49:17 ouster Exp Locker: brent $ SPRITE (Berkeley)";
  61. #endif not lint
  62.  
  63.  
  64. #include <stdio.h>
  65. #include <sys/file.h>
  66. #include <sys/time.h>
  67. #include <sys/resource.h>
  68.  
  69. static char buffer[16384];
  70.  
  71. main(argc, argv)
  72. int argc;
  73. char **argv;
  74. {
  75.     int cnt, repeats, kBytes, fd, count, i;
  76.     double msPer, micros;
  77.     struct rusage begin ,end;
  78.     struct timeval start, stop;
  79.     struct timezone tz;
  80.  
  81.     if (argc != 4) {
  82.     fprintf(stderr, "Usage:  %s fileName kBytes count\n",
  83.         argv[0]);
  84.     exit(1);
  85.     }
  86.     kBytes = atoi(argv[2]);
  87.     repeats = atoi(argv[3]);
  88.  
  89. #ifdef GETRUSAGE
  90.     getrusage(RUSAGE_SELF, &begin);
  91. #else
  92.     gettimeofday(&start, (struct timezone *) NULL);
  93. #endif
  94.  
  95.     for (count = 0 ; count < repeats; count++) {
  96.     fd = open(argv[1], O_WRONLY|O_CREAT|O_TRUNC, 0700);
  97.     if (fd < 0) {
  98.         fprintf(stderr, "Couldn't create %s.\n", argv[1]);
  99.         exit(1);
  100.     }
  101.     for (i = kBytes; i > 0; ) {
  102.         if (i > 16) {
  103.         if (write(fd, buffer, 16384) < 0) {
  104.             fprintf(stderr, "Error while writing.\n");
  105.             exit(1);
  106.         }
  107.         i -= 16;
  108.         } else {
  109.         if (write(fd, buffer, 1024*i - 1) < 0) {
  110.             fprintf(stderr, "Error while writing.\n");
  111.             exit(1);
  112.         }
  113.         i = 0;
  114.         }
  115.     }
  116.     if (close(fd) != 0) {
  117.         fprintf(stderr, "Error closing %s after writing.\n",
  118.             argv[1]);
  119.         exit(1);
  120.     }
  121.     fd = open(argv[1], O_RDONLY, 0700);
  122.     if (fd < 0) {
  123.         fprintf(stderr, "Couldn't open %s to read it back.\n",
  124.             argv[1]);
  125.         exit(1);
  126.     }
  127.     while (1) {
  128.         cnt = read(fd, buffer, 16384);
  129.         if (cnt < 16384) break;
  130.     }
  131.     if (close(fd) != 0) {
  132.         fprintf(stderr, "Error closing %s after reading.\n",
  133.             argv[1]);
  134.         exit(1);
  135.     }
  136.     if(unlink(argv[1]) != 0) {
  137.         fprintf(stderr, "Error removing %s.\n", argv[1]);
  138.         exit(1);
  139.     }
  140.     }
  141. #ifdef GETRUSAGE
  142.     getrusage(RUSAGE_SELF, &end);
  143.     micros = (end.ru_utime.tv_sec + end.ru_stime.tv_sec
  144.         - begin.ru_utime.tv_sec - begin.ru_stime.tv_sec)*1000000
  145.         + (end.ru_utime.tv_usec - begin.ru_utime.tv_usec)
  146.         + (end.ru_stime.tv_usec - begin.ru_stime.tv_usec);
  147. #else
  148.     gettimeofday(&stop, (struct timezone *) NULL);
  149.     micros = 1000000*(stop.tv_sec - start.tv_sec)
  150.         + stop.tv_usec - start.tv_usec;
  151. #endif
  152.     msPer = (micros/repeats/1000.0);
  153.     printf("Time per iteration: %.2f milliseconds\n", msPer);
  154. }
  155. @
  156.  
  157.  
  158. 1.2
  159. log
  160. @First version debugged now.
  161. @
  162. text
  163. @d27 1
  164. a27 1
  165. static char rcsid[] = "$Header: /sprite/src/benchmarks/crtdel/RCS/crtdel.c,v 1.1 89/09/13 11:29:07 ouster Exp Locker: ouster $ SPRITE (Berkeley)";
  166. d49 1
  167. a49 1
  168.     fprintf(stderr, "Usage:  %s fileName numBytes count\n",
  169. @
  170.  
  171.  
  172. 1.1
  173. log
  174. @Initial revision
  175. @
  176. text
  177. @d27 1
  178. a27 1
  179. static char rcsid[] = "$Header: protoPub.c,v 1.3 87/01/04 17:28:56 andrew Exp $ SPRITE (Berkeley)";
  180. d70 1
  181. a70 1
  182.         if (write(1, buffer, 16384) < 0) {
  183. d76 1
  184. a76 1
  185.         if (write(1, buffer, 1024*i - 1) < 0) {
  186. @
  187.